﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;

namespace UnitDriven
{
    [AttributeUsage(AttributeTargets.Method)]
    public sealed class ExpectedExceptionAttribute : Attribute
    {
        private Type _exceptionType;
        public Type ExceptionType { get { return _exceptionType; } }

        public ExpectedExceptionAttribute(Type exceptionType)
        {
#if NETFX_CORE
            if (!typeof(Exception).GetTypeInfo().IsAssignableFrom(exceptionType.GetTypeInfo()))
#else
            if (!typeof(Exception).IsAssignableFrom(exceptionType))
#endif
                throw new ArgumentException(
                  string.Format(CultureInfo.CurrentCulture, ""), // Properties.Resources.ExpectedExceptionDoesNotInheritFromException, exceptionType),
                  "exceptionType");

            _exceptionType = exceptionType;
        }
    }
}
